﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="ProgId" content="FrontPage.Editor.Document">
<link rel="STYLESHEET" type="text/css" id="SkinStyleSheet">
<title>WebNoteEditor</title>
<style type="text/css">
#objListView{
	width:100%;border-collapse: collapse;
}
#objListView th{
	padding-top:3px;padding-bottom:3px;background:#f7f7f7
}
#objListView td{
	text-align:center;font:9pt
}
a:visited,a:link {COLOR: #0000FF; TEXT-DECORATION: underline;cursor:pointer;font-size:8pt}
a:hover,a:active{COLOR: #FF0000; TEXT-DECORATION: underline; cursor: pointer; font-size: 8pt}

a.link{
	width:330px;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;
}
</style>
<script language="javascript" type="text/javascript" src="../script/windialog.js"></script>
<script language="javascript" type="text/javascript" src="../script/ie2w3c-min.js"></script>

<script language="javascript">
window.onload=function()
{
	renderWindowAsIE(window);
	
	document.getElementById("btnSelectAll").onclick=function(){EditorWindow._FormCheckBoxSelectAll("inputImportFiles",document);};
	document.getElementById("btnUnSelectAll").onclick=function(){EditorWindow._FormCheckBoxUnSelectAll("inputImportFiles",document);};
	
	var i,elems;
	elems=document.getElementsByName("inputImportFiles");
	for(i=0;i<elems.length;i++)
	{
		if (elems[i].getAttribute("extName")!="")
		{
			elems[i].checked=true;
		}
	}
	elems=null
	AutoResizeDialogWindow();
}

window.onbeforeunload=function()
{
	
}

function remoteFileInfo(sURL)
{
	var extName=EditorWindow.getFileExt(sURL);
	if (EditorWindow.$config.allow_upload_file_ext.isInArray(extName))
	{
		this.extName=extName;
		this.filesize=0;
	}
	else
	{
		if (EditorWindow.$config.checkRemoteFileInfo)
		{
			EditorWindow.xmlhttp.open("HEAD",sURL,false);
		    EditorWindow.xmlhttp.send(null);
			var contentType=EditorWindow.xmlhttp.getResponseHeader("Content-Type");
			this.extName=contentType.replace("image/","");
			this.size=EditorWindow.xmlhttp.getResponseHeader("Content-Length");
		}
		else
		{
			//imgSrc="../images/filetype/unknow.gif";
			this.extName="?";
			this.filesize=0;
		}
	}
}

function LoadData()
{
	var i,extName,imgSrc,canImport,r,extNameAttribute;
	var files=EditorWindow.getAllFiles().split("|");

	for (i=0;i<files.length;i++)
	{
		if (EditorWindow.isRemoteWebSiteFile(files[i]))
		{
	        r=new remoteFileInfo(files[i]);
			
			extName=r.extName;
			
			if (extName=="?")
			{
				extNameAttribute="";
			}
			else
			{
				extNameAttribute=extName;
			}
			
			document.write("<tr style='padding-top:2;padding-bottom:2;'>");
	        document.write("<td style='text-align:left;padding-left:2;width:380px;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;'>");
	        document.write("<input type='checkbox' name='inputImportFiles' value='"+files[i]+"' extName='"+extNameAttribute+"'>");
			document.write("<a href='"+files[i]+"' target='_blank' class='link'>"+files[i]+"</a></td>");
			document.write("<td>"+extName+"</td>");
			document.write("<td>"+EditorWindow.lang_state_waitforimport+"</td>");
	        document.write("</tr>");
			r=null;
		}
	}
}



function __btnOk_onclick()
{
	__importRemoteFile_loop();
}

function __btnCancel_onclick()
{
	EditorWindow.$ajax.abort();
	window.close();
}


function __importRemoteFile_loop()
{
	document.getElementById("btnOk").disabled=true;
	var elems,i,returnValue,root;
	var returnvalue,fileurl,errordescription
	elems=document.getElementsByName("inputImportFiles");
	for(i=0;i<elems.length;i++)
	{
		this.disabled="disabled";
		if(elems[i].checked)
		{
			window.thiselem=elems[i];
			elems[i].scrollIntoView();
			elems[i].parentElement.parentElement.style.cssText="background-color: #EFF3FF; border: 1 solid #94BEEF";
			EditorWindow.$ajax.load({url:EditorWindow.$config.isapi+"/importremotefileprocess."+EditorWindow.$config.isapi,method:"POST",data:"remotefileurl="+elems[i].value+"&fileextname="+elems[i].getAttribute("extName"),type:"xml",onreadystatechange:__statechange,async:true});
			return;
		}
	}
	elems=null;
	
	window.close();
}

function __statechange()
{
	if(EditorWindow.$ajax.xmlhttp.readyState==4)
	{
		if (EditorWindow.$ajax.xmlhttp.status==200)
		{
			var root=EditorWindow.$ajax.xmlhttp.responseXML;
			var returnvalue=root.getElementsByTagName("returnvalue")[0].firstChild.nodeValue;
			var fileurl="";
			var errordescription="";
			if (returnvalue=="true")
			{
				fileurl=root.getElementsByTagName("fileurl")[0].firstChild.nodeValue;
				window.thiselem.parentNode.nextSibling.nextSibling.innerText=EditorWindow.lang_state_import_ok;
				EditorWindow.__MMreplace(window.thiselem.value,fileurl);
			}
			else
			{
				errordescription=root.getElementsByTagName("errordescription")[0].firstChild.nodeValue;
				alert(errordescription);
				window.thiselem.parentNode.nextSibling.nextSibling.innerText=EditorWindow.lang_state_import_error;
			}
			root=null;
		}
		window.thiselem.checked=false;
		__importRemoteFile_loop();
	}
}


</script>

</head>

<body class="dialog">
<script language="javascript" type="text/javascript">dialogTitle("lang_text_importremotefiles");</script>
<table border="0" width="100%">
  <tr>
    <td valign="top" >
      <div style="overflow: auto; height: 300px; background-color: #FFFFFF; padding: 6">
      <table id="objListView" border="1" width="100%" cellspacing="0" cellpadding="0">
        <tr>
			<th><script type="text/javascript" language="javascript">dialogPrintlang("lang_url");</script></th>
			<th width="width:36px;text-align:center"><script type="text/javascript" language="javascript">dialogPrintlang("lang_filetype");</script></th>
			<th width="width:60px"><script type="text/javascript" language="javascript">dialogPrintlang("lang_state");</script></th>
        </tr>
		<script Language="javascript">
			LoadData();
		</script>
      </table>
      </div>
    </td>
  </tr>
  <tr>
    <td valign="top" align="right">
		<script type="text/javascript" language="javascript">
			document.write("<input type=\"button\" value=\""+EditorWindow.lang_button_selectall+"\" id=\"btnSelectAll\" class=\"SysBtn5\">");
			document.write("<input type=\"button\" value=\""+EditorWindow.lang_button_unselectall+"\" id=\"btnUnSelectAll\" class=\"SysBtn5\">");
			
			PrintButtons2();
		</script>
      
    </td>
  </tr>
</table>
</body>
</html>
